package com.suncaper.wcss.web.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.suncaper.wcss.common.BaseConstant;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.suncaper.wcss.common.JsonResponse;
import com.suncaper.wcss.service.DictionaryService;
import com.suncaper.wcss.model.domain.Dictionary;

import java.util.List;


/**
 *
 *  前端控制器
 *
 *
 * @author lxp
 * @since 2021-11-12
 * @version v1.0
 */
@Controller
@RequestMapping("/dictionary")
public class DictionaryController {

    private final Logger logger = LoggerFactory.getLogger( DictionaryController.class );

    @Autowired
    private DictionaryService dictionaryService;

    /**
     * 获取某个类别的所有数据字典
     */
    @GetMapping("/getDictionaryByType")
    @ResponseBody
    public JsonResponse getDictionaryByType(String type){
        QueryWrapper<Dictionary> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(Dictionary::getType,type).ne(Dictionary::getParentId, BaseConstant.PARENT_ID);
        List<Dictionary> list = dictionaryService.list(wrapper);
        return JsonResponse.success(list);
    }
}

